package org.jeecg.modules.geo.service.resolve.impl;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollUtil;
import org.jeecg.modules.geo.model.dto.AreasDTO;
import org.jeecg.modules.geo.model.dto.DeviceDTO;
import org.jeecg.modules.geo.model.dto.GeoDTO;
import org.jeecg.modules.geo.model.dto.PointCloudDTO;
import org.jeecg.modules.geo.model.vo.AreasVO;
import org.jeecg.modules.geo.model.vo.DeviceVO;
import org.jeecg.modules.geo.model.vo.GeoVO;
import org.jeecg.modules.geo.model.vo.PointCloudVO;
import org.jeecg.modules.geo.service.resolve.IGeoResolve;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

@Service
public class GeoResolveImpl implements IGeoResolve {

    @Autowired
    private AreasGeoResolveServiceImpl areasGeoResolveService;

    @Autowired
    private DevsGeoResolveServiceImpl devsGeoResolveService;

    @Autowired
    private CloudsGeoResolveServiceImpl cloudsGeoResolveService;

    @Override
    public GeoVO resolve(GeoDTO geoDTO, Long projectId) {
        //设备数据
        GeoVO geoVO = new GeoVO();
        List<DeviceDTO> devs = geoDTO.getDevs();
        if (CollUtil.isNotEmpty(devs)) {
            this.devsGeoResolveService.resolveDevs(devs, projectId);
            List<DeviceVO> results = devs.stream().map(it -> BeanUtil.copyProperties(it, DeviceVO.class)).collect(Collectors.toList());
            geoVO.setDevs(results);
        }
        //区域数据
        List<AreasDTO> areas = geoDTO.getAreas();
        if (CollUtil.isNotEmpty(areas)) {
            this.areasGeoResolveService.resolveAreas(areas, projectId);
            List<AreasVO> results = areas.stream().map(it -> BeanUtil.copyProperties(it, AreasVO.class)).collect(Collectors.toList());
            geoVO.setAreas(results);
        }
        //点云数据
        List<PointCloudDTO> pointCloud = geoDTO.getPointCloud();
        if (CollUtil.isNotEmpty(pointCloud)) {
            this.cloudsGeoResolveService.resolveCloud(pointCloud, projectId);
            List<PointCloudVO> results = pointCloud.stream().map(it -> BeanUtil.copyProperties(it, PointCloudVO.class)).collect(Collectors.toList());
            geoVO.setPointCloud(results);
        }
        return geoVO;
    }


}
